{template 'common/header'}
<script type="text/javascript" src="./resource/script/kindeditor/kindeditor-min.js"></script>
 <link type="text/css" rel="stylesheet" href="./resource/style/daterangepicker.css" />
<script type="text/javascript" src="./resource/script/daterangepicker.js"></script>
<ul class="nav nav-tabs">
	<li class="active"><a href="{php echo create_url('site/module', array('do' => 'Yuyue','op'=>'post', 'name' => 'we7car','weid'=>$weid));}">添加预约</a></li>	
	<li><a href="{php echo create_url('site/module', array('do' => 'Yuyue','op'=>'list', 'name' => 'we7car','weid'=>$weid));}">预约管理</a></li>
	<li ><a href="{php echo create_url('site/module', array('do' => 'Yuyue','op'=>'show', 'name' => 'we7car','weid'=>$weid));}">预约订单</a></li>
</ul>
<script>
$(function() {
	 
	$('#date-range').daterangepicker({
        format: 'YYYY-MM-DD',
        startDate: $(':hidden[name=start]').val(),
        endDate: $(':hidden[name=end]').val(),
        locale: {
            applyLabel: '确定',
            cancelLabel: '取消',
            fromLabel: '从',
            toLabel: '至',
            weekLabel: '周',
            customRangeLabel: '日期范围',
            daysOfWeek: moment()._lang._weekdaysMin.slice(),
            monthNames: moment()._lang._monthsShort.slice(),
            firstDay: 0
        }
    }, function(start, end){
        $('#date-range .date-title').html(start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD'));
        $(':hidden[name=start]').val(start.format('YYYY-MM-DD'));
        $(':hidden[name=end]').val(end.format('YYYY-MM-DD'));
    });
});
</script>
	<div class="main">
		<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
	<h4 >添加微预约信息</h4>
	<table  class="tb">
		<tbody>			
			<tr>
				<td><label for="">是否开启</label></td>
				<td>
					<label for="isshow1" class="radio inline"><input type="radio" name="isshow" value="1" id="isshow1" {if $item['isshow'] == 1}  checked="true" {/if}> 开启</label>&nbsp;&nbsp;&nbsp;
					<label for="isshow0" class="radio inline"><input type="radio" name="isshow" value="0" id="isshow0"  {if $item['isshow'] == 0}  checked="true" {/if}> 关闭</label>
				</td>
			</tr>
			<tr>
				<td><label for="">预约类型</label></td>
				<td>
					<label for="yytype1" class="radio inline"><input type="radio" name="yytype" value="1" id="yytype1" {if $item['yytype'] == 1}  checked="true" {/if}> 预约试驾</label>&nbsp;&nbsp;&nbsp;
					<label for="yytype2" class="radio inline"><input type="radio" name="yytype" value="2" id="yytype2"  {if $item['yytype'] == 2}  checked="true" {/if}> 预约保养</label>
					<div class="help-block">每个类型只能有一条预约，多个预约的话，以最新一条为准</div>					
				</td>
			</tr>				
			<tr>
				<td>标题</td>
				<td>
					<input type="text" id="" class="span7" placeholder="" name="title" value="{$item['title']}">
				</td>
			</tr>
			<tr>
				<th>预约说明</th>
				<td>
					<textarea style="height:50px;" name="description" class="span7" cols="60">{$item['description']}</textarea>
					<div class="help-block">用于图文显示的简介</div>
				</td>
			</tr>					
			<tr>
				<td>活动日期</td>
				<td>
					<button style="margin:0;" class="btn span5" id="date-range" type="button"><span class="date-title">{php echo date('Y-m-d', $item['start_time'])} 至 {php echo date('Y-m-d', $item['end_time'])}</span> <i class="icon-caret-down"></i></button>
					<input name="start" type="hidden" value="{php echo date('Y-m-d', $item['start_time'])}" />
					<input name="end" type="hidden" value="{php echo date('Y-m-d', $item['start_time'])}" />
				</td>
			</tr> 
	
			<tr>
				<td>预约电话</td>
				<td>
					<input type="text" id="" class="span4" placeholder="" name="mobile" value="{$item['mobile']}">
				</td>
			</tr>
			<tr>
				<td>订单头部图片</td>
				<td>
					{php echo tpl_form_field_image('topbanner', $item['topbanner']);}
				</td>
			</tr>	
			<tr>
				<td>重命名订单</td>
				<td>
					<input type="text" id="" class="span4" placeholder="我的订单" name="typename1" value="{$item['typename1']}">
				</td>
			</tr>
			<tr>
				<td>重命名订单说明</td>
				<td>
					<input type="text" id="" class="span4" placeholder="订单说明" name="typename2" value="{$item['typename2']}">
				</td>
			</tr>
			<tr>
				<td>重命名订单电话</td>
				<td>
					<input type="text" id="" class="span4" placeholder="订单电话" name="typename3" value="{$item['typename3']}">
				</td>
			</tr>	
			<tr>
				<td>底部版权</td>
				<td>
					<input type="text" id="" class="span4" placeholder="底部版权" name="copyright" value="{$item['copyright']}">
				</td>
			</tr>				

			<tr>
				<td>分享好友地址</td>
				<td>
					<input type="text" id="" class="span7" placeholder="分享好友地址" name="shareurl" value="{$item['shareurl']}">
					<div class="help-block">分享好友地址，带http://，不填写在分享预约页面，为空则无法查询预约</div>					
				</td>
			</tr>			
 			<tr>
				<td>预约地址</td>
				<td>
					<input type="text" id="" class="span7" placeholder="" name="address" value="{$item['address']}">
				</td>
			</tr>	
			<tr>
				<td><label for="">详细地址</label></td>
				<td><div class="input-append"><input type="text" id="address" name="address" value="{$item['address']}"  class="span5" /><button type="button" class="btn" name="submit" value="搜索" onclick="bmap.searchMapByAddress($('#address').val())">搜索</button></div><span class="help-block">可以通过查询地址，快速定位地图位置。</span></td>
			</tr>
			<tr>
				<td><label for="">坐标：</label></td>
				<td><input type="text" name="location_x" id="lng" value="{$item['location_x']}"  class="span3" /> - <input type="text" id="lat" name="location_y" value="{$item['location_y']}"  class="span3" /></td>
			</tr>
		
			<tr>
				<td></td>
				<td><div id="baidumap" style="width:500px; height:300px;"></div></td>
			</tr>
 		</tbody>
	</table>
	<h4 class="alert-heading">订单内容设置</h4>	
	<table id="listTable" class="table table-bordered table-hover dataTable">
		<thead>
			<tr>
				<th style="width:80px">字段类型</td>
				<th style="width:120px">字段名称</td>
				<th style="width:120px">初始内容</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>单行文字：</td>
				<td>
					<input name="keyword" type="text" disabled="disabled" class="wizard-ignore" value="联系人" readonly="readonly"></td>
				<td>
					<input name="add[order][]" type="text" disabled="disabled" class="wizard-ignore" value="请输入您的名字" readonly="readonly"></td>

				<td>
					<label class="checkbox inline"><input type="checkbox"  {if $item['name_show'] == 1}checked="checked"{/if}  name="name_show" value="1">是否显示<label>
				</td>
			</tr>
			<tr>
				<td>单行文字：</td>
				<td>
					<input name="keyword" type="text" disabled="disabled" class="wizard-ignore" value="联系电话" readonly="readonly"></td>
				<td>
					<input name="add[order][]" type="text" disabled="disabled" class="wizard-ignore" value="请输入您的电话" readonly="readonly"></td>

				<td>
					<label class="checkbox inline"><input type="checkbox"  {if $item['tel_show'] == 1}checked="checked"{/if} name="tel_show" value="1">是否显示<label>
				</td>
			</tr>
			<tr>
				<td>日期选择：</td>
				<td>
					<input name=" " type="text" disabled="disabled" class="wizard-ignore" value="预约日期" onchange="$('odid').value='请输入'+this.value;"></td>
				<td>
					<input name="add[order][]" type="text" disabled="disabled" id="odid" class="wizard-ignore" value="请输入预约日期"></td>

				<td>
					<label class="checkbox inline"><input type="checkbox"  {if $item['date_show'] == 1}checked="checked"{/if}  name="date_show" value="1">是否显示<label>
				</td>
			</tr>
			<tr>
				<td>时间选择：</td>
				<td>
					<input name=" " type="text" disabled="disabled" class="wizard-ignore" value="预约时间" onchange="$('odid').value='请输入'+this.value;"></td>
				<td>
					<input name="add[order][]" type="text" disabled="disabled" id="odid" class="wizard-ignore" value="请输入预约时间"></td>

				<td>
					<label class="checkbox inline"><input type="checkbox"  {if $item['time_show'] == 1}checked="checked"{/if}  name="time_show" value="1">是否显示<label>
				</td>
			</tr>
			<?php for($i=0;$i<15;$i++){?>
			<tr id="trtxt{$i}" {if ($i>0 && empty($trtxt[$i]['txt']))}style="display:none"{/if}>
				<td>输入增加的内容：</td>
				<td>
					<input type="text" name="txt{$i}" id="txt{$i}" value="{$trtxt[$i]['txt']}"></td>
				<td>
					<input name="value{$i}" id="value{$i}" type="text" value="{$trtxt[$i]['value']}"></td>
				<td>
					<p>{if ($i<14 )}<a class="btnGrayS vm" id="add{php echo($i+1);}" href="javascript:doaddit({php echo($i+1)})" {if !empty($trtxt[$i+1]['txt'])}style="display:none"{/if}>添加</a>{/if}　<a href="javascript:dodelit({$i})">删除</a></p>
				</td>
			</tr>
			<?php }?>
			
			<?php for($i=0;$i<5;$i++){?>
			<tr id="strtxt{$i}" {if ($i>0 && empty($strtxt[$i]['select']))}style="display:none"{/if}>
				<td width="120">下拉框{php echo($i+1)}：</td>
				<td><input type="text" name="select{$i}" value="{$strtxt[$i]['select']}" id="select{$i}"></td>
				<td><input name="svalue{$i}" id="svalue{$i}" type="text" value="{$strtxt[$i]['svalue']}" placeholder="每个选项之间以“|”分割"></td>
				<td><p>{if ($i<4)}<a class="btnGrayS vm" id="sadd{php echo($i+1);}" href="javascript:sdoaddit({php echo($i+1);})" {if !empty($strtxt[$i+1]['select'])}style="display:none"{/if}>添加</a>{/if}　<a href="javascript:sdodelit({$i})">删除</a></p>
				</td>
			</tr>
			<?php }?>
			<tr>
				<td>多行文字：</td>
				<td>
					<input name="datename" type="text" value="{$item['datename']}"></td>
				<td>
					<input name="add[order][]" type="text" disabled="disabled" value="请留言" readonly="readonly"></td>
				<td>订单默认项</td>
			</tr>
		</tbody>
	</table>
	<table>
		<tr>
			<td></td>
			<td>
				<button type="submit" class="btn btn-primary span3" name="submit" value="提交">提交</button>
				<input type="hidden" name="token" value="{$_W['token']}" />
			</td>
		</tr>
	</table>
 </div>
 					
				
<script type="text/javascript">
KindEditor.ready(function(K) {
	var editor = KindEditor.editor({
		allowFileManager : true,
		uploadJson : "./index.php?act=attachment&do=upload",
		fileManagerJson : "./index.php?act=attachment&do=manager",
 
	});
	$("#file_upload-button").click(function() {
		editor.loadPlugin("multiimage", function() {
			editor.plugin.multiImageDialog({
				imageUrl : $("#upload-image-url-logo").val(),
				clickFn : function(urlList) {
						var div =$('#fileList');
						//div.html('');
						K.each(urlList, function(i, data) {
							html='<li class="imgbox"><a class="thumb_close" href="javascript:void(0)" title="删除"></a><input type="hidden" value="'+data.filename+'" name="thumb_url[]"><span class="item_box"><img src="'+data.url+'"></span></li>';
							div.append(html);
						});
						editor.hideDialog();
					}
		});
		});
	});
});	
$(".btn-primary").click(function() {
	title=$("#title").val();
	if(title==''){
		message('请选择车型名称');
		return false;
	}
	
	bid=$("#bid").val();
	sid=$("#sid").val();
	if(bid==0 || sid==0){
		message('请选择车型或者车系');
		return false;
	}

});
 
	function fetchseries(bid){
		$.get("{php echo create_url('site/module', array('do' => 'getseries', 'name' => 'we7car'))}&bid="+bid,
		function(data){
			if(data.status==1){
				html='<option value="0">请选择车系</option>';
				list=data.list;
				for(var i=0;i<list.length;i++){
					//alert();
					html+= '<option value="'+list[i].id+'">'+list[i].title+'</option>';
				}
				$("#sid").html(html);
			}		
		}, "json");
	}	
</script>	
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>  
<script type="text/javascript">
 var bmap = {
	'option' : {
		'lock' : false,
		'container' : 'baidumap',
		'infoWindow' : {'width' : 250, 'height' : 100, 'title' : ''},
		'point' : {'lng' : 116.403851, 'lat' : 39.915177}
	},
	'init' : function(option) {
		var $this = this;
		$this.option = $.extend({},$this.option,option);
		$this.option.defaultPoint = new BMap.Point($this.option.point.lng, $this.option.point.lat);
		$this.bgeo = new BMap.Geocoder();
		$this.bmap = new BMap.Map($this.option.container);
		$this.bmap.centerAndZoom($this.option.defaultPoint, 15);
		$this.bmap.enableScrollWheelZoom();
		$this.bmap.enableDragging();
		$this.bmap.enableContinuousZoom();
		$this.bmap.addControl(new BMap.NavigationControl());
		$this.bmap.addControl(new BMap.OverviewMapControl());
		//添加标注
		$this.marker = new BMap.Marker($this.option.defaultPoint);
		$this.marker.setLabel(new BMap.Label('请您移动此标记，选择您的坐标！', {'offset':new BMap.Size(10,-20)}));
		$this.marker.enableDragging();
		$this.bmap.addOverlay($this.marker);
		//$this.marker.setAnimation(BMAP_ANIMATION_BOUNCE);
		$this.showPointValue($this.marker.getPosition());
		//拖动地图事件
		$this.bmap.addEventListener("dragging", function() {
			$this.setMarkerCenter();
			$this.option.lock = false;
		});
		//缩入地图事件
		$this.bmap.addEventListener("zoomend", function() {
			$this.setMarkerCenter();
			$this.option.lock = false;
		});
		//拖动标记事件
		$this.marker.addEventListener("dragend", function (e) {
			$this.showPointValue();
			$this.showAddress();
			$this.bmap.panTo(new BMap.Point(e.point.lng, e.point.lat));
			$this.option.lock = false;
			$this.marker.setAnimation(null);
		});
	},
	'searchMapByAddress' : function(address) {
		var $this = this;
		 $this.bgeo.getPoint(address, function (point) {
			if (point) {
				$this.showPointValue();
				$this.showAddress();
				$this.bmap.panTo(point);
				$this.setMarkerCenter();
			}
		});
	},
	'searchMapByPCD' : function(address) {
		var $this = this;
		$this.option.lock = true;
		$this.searchMapByAddress($('#sel-provance').val()+$('#sel-city').val()+$('#sel-area').val());
	},
	'setMarkerCenter' : function() {
		var $this = this;
		var center = $this.bmap.getCenter();
		$this.marker.setPosition(new BMap.Point(center.lng, center.lat));
		$this.showPointValue();
		$this.showAddress();
	},
	'showPointValue' : function() {
		var $this = this;
		var point = $this.marker.getPosition();
		$('#lng').val(point.lng);
		$('#lat').val(point.lat);
	},
	'showAddress' : function() {
		var $this = this;
		var point = $this.marker.getPosition();
		$this.bgeo.getLocation(point, function (s) {
			if (s) {
				$('#address').val(s.address);
				if (!$this.option.lock) {
					cascdeInit(s.addressComponents.province,s.addressComponents.city,s.addressComponents.district);
				}
			}
		});
	}
};
$(function(){
	var option = {};
	{if !empty($item['location_x']) && !empty($item['location_y'])}
	option = {'point' : {'lng' : '{$item['location_x']}', 'lat' : '{$item['location_y']}'}}
	{/if}
	bmap.init(option);
});
</script>
<script>
function dodelit(i) {
	document.getElementById("txt" + i).value = "";
	document.getElementById("value" + i).value = "";
	if (i != 0) {
		document.getElementById("trtxt" + i).style.display = "none";
		document.getElementById("add" + i).style.display = "";
	}
}
function doaddit(i) {
	document.getElementById('trtxt' + i).style.display = "";
	document.getElementById('add' + i).style.display = "none";
}
function sdodelit(i) {
	document.getElementById("select" + i).value = "";
	document.getElementById("svalue" + i).value = "";
	if (i != 0) {
		document.getElementById("strtxt" + i).style.display = "none";
		document.getElementById("sadd" + i).style.display = "";
	}
}
function sdoaddit(i) {
	document.getElementById('strtxt' + i).style.display = "";
	document.getElementById('sadd' + i).style.display = "none";
}
</script>
{template 'common/footer'}

